package com.shunhe.storage.support.util;

import android.content.Context;
import android.content.pm.PackageManager;
import android.util.Log;

public class ManifestUtil {

    //不同的类型要区别获取，以下是布尔类型的
    public static boolean getAppMetaDataBool(Context context, String metaName, boolean defaultValue) {
        try {
            //application标签下用getApplicationinfo，如果是activity下的用getActivityInfo
            boolean value = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA)
                    .metaData.getBoolean(metaName, defaultValue);
            Log.d("meta-data", metaName + " = " + value);
            return value;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return defaultValue;
        }
    }

    //不同的类型要区别获取，以下是String的
    public static String getAppMetaDataString(Context context, String metaName, String defaultValue) {
        try {
            //application标签下用getApplicationinfo，如果是activity下的用getActivityInfo
            String value = context.getPackageManager()
                    .getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA)
                    .metaData.getString(metaName, defaultValue);
            Log.d("meta-data", metaName + " = " + value);
            return value;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
            return defaultValue;
        }
    }
}
